﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LibrarySystem
{
    public partial class SalesEmployees : Form
    {
        AppManager LIB = new AppManager();
        public SalesEmployees()
        {
            InitializeComponent();
        }

        private void SalesEmployees_Load(object sender, EventArgs e)
        {
            LIB.ComboDisplay(comboBox1, "select * from EMPLOYEE where 'المحاسبة' = الوظيفة", "EMPLOYEE", "الإسم");
            label2.Hide();
            label3.Hide();
            label4.Hide();
            dateTimePicker1.Hide();
            dateTimePicker2.Hide();
            comboBox1.Text = "";
            button7.Enabled = false;
            //radioButton1.Checked = false;
            //radioButton2.Checked = false;
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            comboBox1.Text = "";
            label2.Hide();
            label3.Hide();
            label4.Show();
            dateTimePicker1.Show();
            dateTimePicker1.Text = DateTime.Now.ToShortDateString();
            dateTimePicker2.Hide();
            button7.Enabled = true;
            label5.Text = "";
            label36.Text = "";
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            comboBox1.Text = "";
            label2.Show();
            label3.Show();
            label4.Hide();
            dateTimePicker1.Show();
            dateTimePicker1.Text = DateTime.Now.ToShortDateString();
            dateTimePicker2.Show();
            dateTimePicker2.Text = DateTime.Now.ToShortDateString();
            button7.Enabled = true;
            label5.Text = "";
            label36.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            label5.Text = "";
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text.Length > 0)
            {
                label5.Text = "";
                label36.Text = "";
                if(radioButton1.Checked == true)
                {
                    LIB.FunSUM("SELECT SUM(الإجمالي_بعد_الخصم) FROM alssafa.dbo.Bill WHERE التاريخ = '"+dateTimePicker1.Text+"' AND اسم_المحاسب = '"+comboBox1.Text+"'",label6);
                    if(label6.Text.Length>0)
                    {
                        label5.Text = label6.Text ;
                    }
                    else
                        label5.Text = "0";

                }
                else if (radioButton2.Checked == true)
                {
                    if (dateTimePicker2.Value >= dateTimePicker1.Value)
                    {
                        LIB.FunSUM("SELECT SUM(الإجمالي_بعد_الخصم) FROM alssafa.dbo.Bill WHERE التاريخ BETWEEN '" + dateTimePicker1.Text + "' AND '" + dateTimePicker2.Text + "' AND اسم_المحاسب = '" + comboBox1.Text + "'", label6);
                        if (label6.Text.Length > 0)
                        {
                            label5.Text = label6.Text;
                        }
                        else
                            label5.Text = "0";
                    }
                    else
                        label36.Text = "أدخل فترة صحيحة";
           
                }

                
            }
            else
                label36.Text = "اختر اسم الموظف";

        }
    }
}
